<template>
  <div class="main">
    <header-back></header-back>
    <div class="wytwBox">
      <span class="wytwSp">写评论</span>
      <div class="texArea">
        <x-textarea v-model="textTxt" :max="200" placeholder="我有话想说..." @on-blur="blurAdjust"></x-textarea>
      </div>
      <button class="sures" v-on:click="sureQuestion">提交评论</button>
    </div>
  </div>
</template>
<script>
import headerBack from "~/components/headerBack";
import { infoTopicComment } from "~/api/identity";
import { XTextarea } from "vux";
import ls from "store2";

export default {
  components: { XTextarea, headerBack },
  data() {
    return {
      textTxt: "",
      sendCount: 0
    };
  },
  mounted(){
     
  },
  methods: {
    sureQuestion() {      
      if (this.textTxt == "") {
        this.$vux.toast.text("请输入您的问题");
        return false;
      }
      this.sendCount += 1;
      if (this.sendCount > 1) return;
      let obj = { topicId: this.$route.query.type, content: this.textTxt };
      infoTopicComment(obj)
        .then(res => {
          if (res) {
            this.$vux.toast.text(res.message);

            this.textTxt = "";
            if(res.code=='0'){
                this.$router.back()
            }
          }
        })
        .catch(error => {
          this.$vux.toast.text("服务器故障，请稍后再试");
        });
    },

    blurAdjust(e) {
      setTimeout(() => {
        if (
          document.activeElement.tagName == "INPUT" ||
          document.activeElement.tagName == "TEXTAREA"
        ) {
          return;
        }

        let result = "pc";
        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
          //判断iPhone|iPad|iPod|iOS
          result = "ios";
        } else if (/(Android)/i.test(navigator.userAgent)) {
          //判断Android
          result = "android";
        }

        if (result != "android") {
          window.scroll(0, 0);
          document.activeElement.scrollIntoViewIfNeeded(true);
        }
      }, 20);
    }
  }
};
</script>

<style lang="less">
.wytwBox {
  width: 100%;
  padding: 0 0.3rem;
  box-sizing: border-box;
  height: auto;
  padding-bottom: 0.3rem;
  padding-top: 0.2rem;
  background: #fff;
  height: 100vh;
  font-size: 0.3rem;

  .wytwSp {
    font-size: 0.3rem;
    font-weight: bold;
    color: rgba(34, 34, 34, 1);
    line-height: 0.42rem;
  }
  .texArea {
    width: 100%;
    height: 3.3rem;
    margin-top: 0.3rem;

    .weui-cell {
      padding: 0;

      .weui-textarea {
        height: 3.3rem;
        background: rgba(250, 250, 250, 1);
        border-radius: 0.1rem;
        font-size: 0.3rem;
      }
    }
  }

  .sures {
    width: 3.2rem;
    height: 0.88rem;
    background: @mainColor;
    border-radius: 0.44rem;
    outline: none;
    border: none;
    display: block;
    margin: 0.6rem auto 0;
    font-size: 0.36rem;

    font-weight: 600;
    color: rgba(255, 255, 255, 1);
    line-height: 0.88rem;
  }
}
</style>
